<!--
 * @Author: your name
 * @Date: 2022-03-10 18:49:26
 * @LastEditTime: 2022-09-29 20:40:20
 * @LastEditors: BigFlower
 * @Description: main page
 * @FilePath: \wochat-vue3-ts-pinia\src\views\home.vue
-->
<template>
  <div class="root">
    <div class="main">
      <div class="nav-layout">
        <img class="avator" :src="avatorUrl" />
        <el-radio-group v-model="currentTab" size="small">
          <el-radio-button
            v-model="currentTab"
            class="tab-icon"
            :label="TAB.CHATS"
          >
            <i class="iconfont icon-chat tab-icon-img" />
          </el-radio-button>
          <el-radio-button
            v-model="currentTab"
            class="tab-icon"
            :label="TAB.CONTACTS"
          >
            <i class="iconfont icon-tongxunlu tab-icon-img"
          /></el-radio-button>
          <el-radio-button
            v-model="currentTab"
            class="tab-icon"
            :label="TAB.FAVORITES"
          >
            <i class="iconfont icon-1box tab-icon-img" />
          </el-radio-button>
          <el-radio-button
            v-model="currentTab"
            class="tab-icon"
            :label="TAB.FILES"
          >
            <i class="iconfont icon-pengyouquan tab-icon-img"
          /></el-radio-button>
        </el-radio-group>
        <div style="flex: 1"></div>
        <el-popover
          v-model="morePopupVisible"
          class="more"
          placement="right-end"
          trigger="click"
          :show-arrow="false"
          popper-class="more-popup"
        >
          <div>
            <div class="more-item" @click="channelClick">Channels Live</div>
            <div class="more-item" @click="feedbackClick">Feedback</div>
            <div class="more-item" @click="backupRestoreClick">
              Backup and Restore
            </div>
            <div class="more-item" @click="settingClick">Settings</div>
          </div>
          <i class="iconfont icon-more"></i>
        </el-popover>
      </div>
      <div class="main-right">
        <wx-chat v-show="currentTab === TAB.CHATS"></wx-chat>
        <div v-if="currentTab === TAB.CONTACTS">Contacts</div>
        <div v-if="currentTab === TAB.FAVORITES">Favorites</div>
        <div v-if="currentTab === TAB.FILES">Files</div>
      </div>
    </div>
  </div>
</template>

<script lang="ts" setup>
import WxChat from "@/views/WxChat.vue";
import { TAB } from "@/common/constant";
import { ref, onMounted } from "vue";
import { storeToRefs } from "pinia";
import { useUserStore } from "@/store/user";

const userStore = useUserStore();
const { avatorUrl } = storeToRefs(userStore);

const currentTab = ref(TAB.CHATS);
const morePopupVisible = ref(false);
const channelClick = () => {
  morePopupVisible.value = false;
};
const feedbackClick = () => {
  morePopupVisible.value = false;
};
const backupRestoreClick = () => {
  morePopupVisible.value = false;
};
const settingClick = () => {
  morePopupVisible.value = false;
};
</script>

<style lang="less" scoped>
.root {
  height: 100%;
  width: 100wh;
  display: flex;
  justify-content: center;
  align-items: center;
  .main {
    height: 80%;
    width: 54%;
    min-width: 800px;
    display: flex;
    justify-content: center;
    align-items: center;
    border-radius: 3px;
    border: 1px solid lightgray;
  }
  .nav-layout {
    width: 50px;
    height: 100%;
    border-radius: 3px 0px 0px 3px;
    background: #2d2d2d;
    display: flex;
    flex-direction: column;

    .avator {
      width: 36px;
      height: 36px;
      align-self: center;
      margin-top: 30px;
    }

    .tab-icon {
      margin-top: 18px;
      .tab-icon-img {
        font-size: 24px;
        height: 32px;
        width: 32px;
      }
      :deep(.el-radio-button__inner) {
        color: rgb(163, 163, 163);
        width: 50px;
        border-radius: 0;
        padding: 0;
        border: 0;
        background-color: transparent;
        text-align: center;
      }
      :deep(.el-radio-button__inner:hover) {
        color: rgb(199, 199, 199);
      }
      :deep(.el-radio-button__orig-radio:checked + .el-radio-button__inner) {
        color: rgb(7, 193, 96);
      }
    }

    .more {
      width: 20px;
      margin-bottom: 16px;
      align-self: center;
      i {
        color: rgb(163, 163, 163);
        font-size: 20px;
      }
      i:hover {
        color: rgb(199, 199, 199);
      }
      :deep(.el-popper) {
        margin-left: 15px;
      }
    }
  }
  .main-right {
    height: 100%;
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
  }
}
</style>
